package edu.qd.learn.day05;

/**
 * @author 布衣
 */
public class StackDemo01 {

    public static void main(String[] args) {

        String sign = "{[(]})";

        if (sign.length() % 2 != 0) {
            System.out.println("括号不匹配");
            return;
        }
        LearnStack<Integer> s1 = new LearnStack<>(sign.length());
        for (int i = 0; i < sign.length(); i++) {
            if (s1.isEmpty()) {
                s1.push((int)sign.charAt(i));
            }else{
                if((int)sign.charAt(i) - s1.peek() == 1 || (int)sign.charAt(i) - s1.peek() == 2){
                    s1.pop();
                }else{
                    s1.push((int)sign.charAt(i));
                }
            }
        }
        System.out.println(s1.isEmpty()?"有效的":"无效的");

    }

}
